package com.sinoair.pkm_ui;

import javax.swing.*;
import java.awt.*;

import static java.awt.GraphicsDevice.WindowTranslucency.*;

/**
 * @author: xueqb
 * @description: jdk7 实现jframe透明窗体示例
 * @date: create in  11:04 2017/9/27
 */
public class TansluFrame extends JFrame {


    public static void main(String[] args) {

//        jdk7判断操作系统是否支持透明窗体的设置
        // Determine what the default GraphicsDevice can support.
        GraphicsEnvironment ge = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();

        boolean isUniformTranslucencySupported = gd
                .isWindowTranslucencySupported(TRANSLUCENT);//是否支持全部统一透明度的窗体

        boolean isPerPixelTranslucencySupported = gd
                .isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);//是否每部分不同透明度的窗体

        boolean isShapedWindowSupported = gd
                .isWindowTranslucencySupported(PERPIXEL_TRANSPARENT);//是否支持异性窗体

        System.out.println("isUniformTranslucencySupported:" + isUniformTranslucencySupported);
        System.out.println("isPerPixelTranslucencySupported:" + isPerPixelTranslucencySupported);
        System.out.println("isShapedWindowSupported:" + isShapedWindowSupported);


        if (isUniformTranslucencySupported) {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame jf = new JFrame("统一透明度");
            jf.setLayout(new GridBagLayout());
            Button bu = new Button("这是个按钮");
            jf.add(bu);
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            jf.setBounds(100, 60, 200, 300);
            jf.setOpacity(0.8f);
            jf.setVisible(true);
        }
    }
}
